/**
 * 
 */
package com.fly.sms.adapter;

import java.util.List;
import java.util.Map;

import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.fly.sms.CommonActivity;
import com.fly.sms.R;

public class UpcontactListAdapter extends IAdapter {
	private List<Map<String, Object>> list = null;

	public UpcontactListAdapter(CommonActivity context,
			List<Map<String, Object>> list) {
		super(context);
		this.list = list;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = context.getView(R.layout.upcontactitem);
		}
		final Map<String, Object> map = list.get(position);
		TextView Name = (TextView) convertView.findViewById(R.id.Name);
		TextView Number = (TextView) convertView.findViewById(R.id.Number);
		Boolean selectall=(Boolean)context.get("selectall");
		CheckBox needupCheckBox = (CheckBox) convertView
				.findViewById(R.id.needup);
		Name.setText(map.get("Name").toString());
		Number.setText(map.get("Number").toString());
		if(selectall){
			needupCheckBox.setChecked(true);
		}else{
			needupCheckBox.setChecked(false);
		}
		needupCheckBox
				.setOnCheckedChangeListener(new OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						List<Map<String, Object>> uplist=(List<Map<String, Object>>)context.get("uplist");
						if(isChecked){
							uplist.remove(map);
							uplist.add(map);
						}else{
							uplist.remove(map);
						}
					}
				});
		return convertView;
	}
}
